<template>
    <div>
        <p>姓名：<input type="text" v-model="ding_name"></p>
        <p>手机号：<input type="text" v-model="phone" @blur="uap"></p>
        <button @click="add">提交订单</button>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            ding_name:'',
            phone:'',
            base_url:'',
            sid:this.$route.query.sid,
            user_id:this.$route.query.user_id
        }
    },
    methods: {
        add(){
            let form_data = new FormData()
            form_data.append('ding_name',this.ding_name)
            form_data.append('phone',this.phone)
            form_data.append('product',this.sid)
            form_data.append('user',this.user_id)
             axios.post('http://127.0.0.1:8000/order/',form_data).then(res=>{
                console.log(res.data)
                if(res.data.code == 200){
                    alert('下单成功')
                    this.$router.push({
                        path:'/show_order',
                        query:{'user_id':this.user_id}
                        })
                }else{
                alert('下单失败')
                }
            })
        },
        uap(){
            if (! /^[1][3,4,5,7,8][0-9]{9}$/.test(this.phone)) {
                alert('手机格式正确')
            } else {
                alert('手机格式错误')
            }
        }
    },
    created() {

    }
}
</script>

<style scoped>

</style>
